#ifndef _STREAM_CONNECTION_H
#define _STREAM_CONNECTION_H

#include "def.h"
#include <shout/shout.h>
#include <QtCore>
#include <QtNetwork>

class StreamConnection : public QThread
{
	Q_OBJECT

public:
	StreamConnection();
	~StreamConnection();

	int setHost(const char *);
	int setPort(const int);
	int setUser(const char *);
	int setPass(const char *);
	int setMountPoint(const char *);
	int setAgent(const char *);
	int setDescription(const char *);
	int setGenre(const char *);
	int setURL(const char *);
	int setPublic(const int);
	int setFormat(const int);
	int setName(const char *);

	int connectShout();
	int connect();

	int close();
	int send(const unsigned char* header, const int header_len,const unsigned char *data, const int size);
	int sendRaw(const unsigned char *data, const int size);

#if DEBUG
signals:
	void logged(const char*);
#endif

private:
	int initializeShout();
	shout_t *shout;

	char * m_strIP;
	int m_nPort;
	char * m_strUser;
	char * m_strPass;
	char * m_strMountPoint;
	char * m_strAgent;
	char * m_strDesc;
	char * m_strGenre;
	char * m_strURL;
	int m_nPublic;
	int m_nFormat;
	char * m_strName;

	QThread *m_lpSendingThread;
	QTcpSocket *m_lpSocket;

	typedef struct _SendData {
		char * data;
		int size;
	} SendData;
	QQueue<SendData*> m_queueData;
	QMutex m_queueLock;

	virtual void run();
	int m_bExit;
	int sendShout(const unsigned char* header, const int header_len,const unsigned char *data, const int size);
	int sendShout(const unsigned char *data, const int size);
};

#endif // _STREAM_CONNECTION_H
